package com.xx.springboot.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.xx.springboot.entity.Student;
import com.xx.springboot.repositry.StudentRepositry;
import com.xx.springboot.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by xiaoxiunique on 2018-8-4.
 */
@RestController
@RequestMapping("/student")
public class StudentController extends ApiController {

    @Autowired
    private StudentRepositry studentRepositry;

    @Autowired
    private IStudentService studentService;

    /**
     * 获取得到所有的学生数据
     * @return
     */
    @GetMapping(value = "/students")
    public List<Student> studentList() {

        return studentRepositry.findAll();
    }

    @GetMapping(value = "/testMybatis")
    public List<Student> getStudentList() {
        return studentService.selectListBySql();
    }

    /**
     * 增加学生
     * @return
     */
    @GetMapping(value = "/add")
    public boolean add() {

        Student student = new Student();
        student.setSize(10);
        student.setCupSize("student");

        return studentService.save(student);
    }
}
